/* ===== RESET AND BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
}

/* ===== MAIN CONTAINER ===== */
#app {
    width: 100%;
    height: 450px;
    position: relative;
    overflow: hidden;
}

/* Adjust height when opened in new tab */
@media (min-height: 500px) {
    body:not(.iframe-mode) #app {
        height: 90vh;
    }
}

/* ===== GAME SCREEN ===== */
#game-screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(to bottom, #87CEEB 0%, #98D8C8 100%);
    position: relative;
}

/* ===== TOP BAR ===== */
#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    z-index: 100;
    gap: 10px;
}

#score-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 18px;
    font-weight: bold;
    color: #FF6B6B;
    background: #FFF3E0;
    padding: 6px 12px;
    border-radius: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-width: 80px;
}

.icon {
    font-size: 20px;
}

#progress-container {
    flex: 1;
    max-width: 200px;
    position: relative;
    height: 24px;
    background: #E0E0E0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

#progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 12px;
}

#progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    font-weight: bold;
    color: #333;
    text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}

#sound-toggle {
    background: #4CAF50;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    min-width: 36px;
    flex-shrink: 0;
}

#sound-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

#sound-toggle:active {
    transform: scale(0.95);
}

#sound-toggle.muted {
    background: #9E9E9E;
}

/* ===== GAME AREA ===== */
#game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;
    overflow-y: auto;
    gap: 12px;
}

/* ===== CHARACTER CONTAINER ===== */
#character-container {
    text-align: center;
    animation: slideInTop 0.5s ease;
}

#character {
    font-size: 60px;
    display: inline-block;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.2));
}

#character.bounce {
    animation: bounce 1s infinite;
}

#character-name {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin-top: 4px;
    background: rgba(255, 255, 255, 0.8);
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
}

/* ===== NEW: FIELD VISUALIZATION STYLES ===== */
#field-visualization {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideInTop 0.5s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 180px;
}

#field-canvas {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

/* ===== SCENARIO CONTAINER ===== */
#scenario-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideInLeft 0.5s ease;
}

#scenario-image {
    font-size: 48px;
    text-align: center;
    margin-bottom: 12px;
    animation: pulse 2s infinite;
}

#scenario-text {
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    text-align: center;
}

/* ===== OPTIONS CONTAINER ===== */
#options-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: slideInRight 0.5s ease;
}

.option-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    text-align: left;
    min-height: 44px;
    touch-action: manipulation;
    position: relative;
    overflow: hidden;
}

.option-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.option-btn:hover::before {
    width: 300px;
    height: 300px;
}

.option-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.option-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.option-btn.correct {
    background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
    animation: correctPulse 0.5s ease;
}

.option-btn.incorrect {
    background: linear-gradient(135deg, #F44336 0%, #E91E63 100%);
    animation: shake 0.5s ease;
}

.option-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== FEEDBACK CONTAINER ===== */
#feedback-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    text-align: center;
    animation: zoomIn 0.5s ease;
}

#feedback-container.hidden {
    display: none;
}

#feedback-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

#feedback-text {
    font-size: 15px;
    line-height: 1.5;
    color: #333;
    margin-bottom: 12px;
}

#next-btn {
    background: linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    min-height: 44px;
    min-width: 120px;
}

#next-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

#next-btn:active {
    transform: translateY(0);
}

/* ===== ANALYTICS PANEL ===== */
#analytics-toggle {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #667eea;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    z-index: 50;
    min-height: 44px;
}

#analytics-toggle:hover {
    background: #667eea;
    color: white;
    transform: scale(1.05);
}

#analytics-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    border-top: 3px solid #667eea;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
    max-height: 40%;
    display: flex;
    flex-direction: column;
    z-index: 60;
}

#analytics-panel.collapsed {
    transform: translateY(100%);
}

#analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #667eea;
    color: white;
}

#analytics-header h3 {
    font-size: 16px;
    margin: 0;
}

#clear-log {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 36px;
    min-width: 36px;
}

#clear-log:hover {
    background: rgba(255, 255, 255, 0.3);
}

#analytics-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    font-size: 13px;
    line-height: 1.6;
}

.log-entry {
    padding: 8px;
    margin-bottom: 6px;
    background: #f5f5f5;
    border-left: 3px solid #667eea;
    border-radius: 4px;
    animation: slideInBottom 0.3s ease;
}

.log-time {
    font-weight: bold;
    color: #667eea;
    margin-right: 8px;
}

.log-action {
    color: #333;
}

/* ===== END SCREEN ===== */
#end-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

#end-screen.hidden {
    display: none;
}

#end-content {
    background: white;
    border-radius: 20px;
    padding: 24px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    max-width: 90%;
    animation: zoomIn 0.5s ease;
}

#trophy {
    font-size: 80px;
    animation: bounce 1s infinite;
}

#end-content h2 {
    font-size: 24px;
    color: #333;
    margin: 12px 0;
}

#final-score {
    font-size: 32px;
    font-weight: bold;
    color: #FF6B6B;
    margin: 12px 0;
}

#performance-summary {
    font-size: 15px;
    color: #666;
    margin: 12px 0;
    line-height: 1.6;
}

#restart-btn {
    background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    margin-top: 12px;
    min-height: 44px;
}

#restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

#restart-btn:active {
    transform: translateY(0);
}

/* ===== ANIMATIONS ===== */
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

@keyframes correctPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes slideInTop {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInLeft {
    from { transform: translateX(-50px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(50px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideInBottom {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes zoomIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 480px) {
    #top-bar {
        padding: 6px 8px;
    }
    
    #score-display {
        font-size: 16px;
        padding: 4px 8px;
        min-width: 70px;
    }
    
    #progress-container {
        max-width: 150px;
    }
    
    #character {
        font-size: 48px;
    }
    
    #character-name {
        font-size: 14px;
    }
    
    #scenario-text {
        font-size: 14px;
    }
    
    .option-btn {
        font-size: 14px;
        padding: 12px 14px;
    }
    
    #game-area {
        padding: 8px;
        gap: 10px;
    }
    
    /* Adjust field visualization for mobile */
    #field-visualization {
        min-height: 140px;
        padding: 8px;
    }
}

@media (min-width: 768px) {
    #game-area {
        padding: 20px;
        gap: 16px;
    }
    
    #options-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    
    /* Larger field visualization for desktop */
    #field-visualization {
        min-height: 220px;
    }
}

/* ===== ACCESSIBILITY ===== */
button:focus {
    outline: 3px solid #FF6B6B;
    outline-offset: 2px;
}

/* ===== SCROLLBAR STYLING ===== */
#analytics-content::-webkit-scrollbar,
#game-area::-webkit-scrollbar {
    width: 8px;
}

#analytics-content::-webkit-scrollbar-track,
#game-area::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#analytics-content::-webkit-scrollbar-thumb,
#game-area::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#analytics-content::-webkit-scrollbar-thumb:hover,
#game-area::-webkit-scrollbar-thumb:hover {
    background: #555;
}